export const scrollto = {
  bind (el, binding, vnode) {
      const modifiers = binding.modifiers;
      const value = binding.value; // 回调函数
      let distance = 0;
      // 检查是否有数字修饰符
      Object.keys(modifiers).forEach(mod => {
          if (!isNaN(mod)) {
              distance = parseInt(mod);
          }
      });
      // 保存上一次滚动位置以确定方向
      let lastScrollTop = el.scrollTop;
      // 创建滚动处理函数
      const handleScroll = function (e) {
          // 获取滚动位置
          const scrollPosition = el.scrollTop;
          // 确定滚动方向 (true=向上滚动/下拉页面，false=向下滚动/上拉页面)
          const isScrollingUp = scrollPosition < lastScrollTop;
          lastScrollTop = scrollPosition;
          // 检查是否是顶部滚动
          if (modifiers.top && isScrollingUp && scrollPosition <= distance) {
              value();
          }
      };
      // 添加滚动事件监听器
      el.addEventListener('scroll', handleScroll);
      // 保存引用以便解绑
      el._onScrolltoHandler = handleScroll;
  },
  unbind (el) {
      // 移除事件监听器
      if (el._onScrolltoHandler) {
          el.removeEventListener('scroll', el._onScrolltoHandler);
          delete el._onScrolltoHandler;
      }
  }
};
